﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using ProjectEuler.Linq;
namespace ProjectEuler.Problems
{
    [EulerProblem(15, 137846528820L)]
    [Description("Starting in the top left corner in a 20 by 20 grid, how many routes are there to the bottom right corner?")]
    internal sealed class Problem015 : EulerProblem
    {
        public override Object Solve()
        {
            var size = 20;
            var buffer = (2L).To(size + 1).ToArray();

            for (int i = 1; i < buffer.Length; i++)
            {
                buffer[i] *= 2;

                for (int j = i + 1; j < buffer.Length; j++)
                {
                    buffer[j] += buffer[j - 1];
                }
            }

            return buffer[buffer.Length - 1];
        }
    }
}
